#pragma once

#pragma comment (lib, "vfw32")

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <tchar.h>
#include <math.h>
#include <stdio.h>
#include <vfw.h>
#include <xmmintrin.h>
#include "MathUtils.h"
#include "MathTypes.h"
#include <fstream>
#include <iostream>

#include <vector>
using std::vector;

class RenderMan
{
public:
	RenderMan();
	virtual ~RenderMan();

public:
	void Initialize(HWND hWnd, UINT32 iWidth, UINT32 iHeight);
	void Shutdown();
	void DrawFrame();
	UINT32 GetFPS();

private:
	void InitTimer();
	TIME GetTime();
	void NoiseEffect();
	void ClearScreen();
	void UpdateTimer();
	void PrintTextInfo();
	void PrintToBuffer(vector<UINT32> &vScrBuffer, UINT32 resX, UINT32 resY, UINT32 dstX, UINT32 dstY, LPSTR lpszText, _PIXEL textColor, LPTSTR lpszFontName, UINT32 fontSize, BOOL bBold, BOOL bItalic);
	void PrintBufferAdditive(const vector<UINT32> &vScrBuffer, UINT32 resX, UINT32 resY);
	void ClearBuffer(vector<UINT32> &vScrBuffer, UINT32 resX, UINT32 resY);
	void Slow_DrawLine(INT32 x1, INT32 y1, INT32 x2, INT32 y2, UINT32 color);

private:
	HWND m_hWnd;
	UINT32 m_iWidth;
	UINT32 m_iHeight;
	UINT32 m_dwByteSize;
	UINT32 m_dwPixelCount;
	vector<UINT32> m_vScreenBuffer;
	vector<UINT32> m_vZBuffer;
	HDRAWDIB m_hDrawDib;
	BITMAPINFOHEADER m_bih;
	TIME m_dFrequency;
	TIME m_dAbsoluteTime;
	TIME m_dLastFrameRefTime;
	TIME m_dStepTime;
	UINT32 m_iFPS;
	vector<UINT32> m_vTextBuffer;
	UINT32 m_iTextBufferWidth;
	UINT32 m_iTextBufferHeight;
	vector<TIME> m_vFpsAuxMean;
	UINT32 m_iFpsAuxIndex;
	TIME m_dFpsAuxSum;
};